import Vue from 'vue';
import Router from 'vue-router';
import CampusBinhai from '@/components/CampusBinhai.vue';
import CampusChashan from '@/components/CampusChashan.vue';
import CampusYueqing from '@/components/CampusYueqing.vue';
import Login from '@/components/Login.vue';
import StudentSystem from '@/components/StudentSystem.vue';

Vue.use(Router);

export default new Router({
  routes: [
    {
      path: '/',
      name: 'CampusBinhai',
      component: CampusBinhai,
    },
    {
      path: '/campus-chashan',
      name: 'CampusChashan',
      component: CampusChashan,
    },
    {
      path: '/campus-yueqing',
      name: 'CampusYueqing',
      component: CampusYueqing,
    },
    {
      path: '/login',
      name: 'Login',
      component: Login,
    },
    {
      path: '/student-system',
      name: 'StudentSystem',
      component: StudentSystem,
      beforeEnter: (to, from, next) => {
        // 检查是否已登录，未登录则重定向到登录页面
        if (!localStorage.getItem('isLoggedin')) {
          next('/login');
        } else {
          next();
        }
      },
    },
  ],
});
